Sys.Application.add_init(pageInit);
var people = new Array();

function pageInit() {
    
    Array.add(people, 'Person0');
    Array.add(people, 'Person1');
    Array.add(people, 'Person2');
    Array.add(people, 'Person3');
    
    writeArray();
}

function writeArray() {
    var sb = new Sys.StringBuilder('<ul>');
    var mask = "<li>{0}</li>";
    for(var x=0; x<people.length; x++) {
        sb.append( String.format(mask, people[x]) );
    }
    sb.append('</ul>');
    $get('peopleDisplay').innerHTML = sb.toString();
}

function addPerson() {
    //add a new item to the Array
    Array.add(people, 'New Person');
    writeArray();
}

function dequeuePerson() {
    //remove the first item
    Array.dequeue(people);
    writeArray();
}

function addPersonAt() {
    //remember this is a zero based index
    //so this is actually inserted as the second element
    Array.insert(people, 1, 'Added here');
    writeArray();
}

function removePerson() {
    //find 'Person3', if found, remove it
    //if not found, do nothing
    Array.remove(people, 'Person3');
    writeArray();
}

function removeAtPerson() {
    //remember this is a zero based index
    //so this is actually removing the second element
    Array.removeAt(people, 1);
    writeArray();
}

